package com.service.business.base.controller;

import com.service.business.base.controller.req.EmailVerifyCodeReq;
import com.service.business.base.controller.req.PhoneVerifyCodeReq;
import com.service.business.base.service.VerifyCodeService;
import com.service.business.member.controller.req.TwoFaReq;
import com.service.business.utils.IpAddressUtil;
import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import com.service.utility.common.UUIDUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <dl>
 * <dt>back-end</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2015</dd>
 * <dd>Company: </dd>
 * <dd>CreateDate: 2019年09月18日</dd>
 * </dl>
 *
 * @author
 */
@Slf4j
@RestController()
@RequestMapping("/open/auth-code")
@Api(tags = "验证码发送类")
public class VerifyCodeController extends BaseController {


    @Autowired
    private VerifyCodeService verifyCodeService;


    @ApiOperation("手机号码验证码发送接口")
    @PostMapping("/phone")
    public BaseResponse sendPhoneVerifyCode(@RequestBody PhoneVerifyCodeReq verifyCodeReq, HttpServletRequest request) {
        String uuid = UUIDUtil.randomUUID();
        log.info("请求开始 验证码发送接口: 请求参数：{}，UUID:{}", verifyCodeReq, uuid);
        verifyCodeReq.setIpAdd(IpAddressUtil.get(request));
        verifyCodeService.send(verifyCodeReq);
        log.info("请求结束： UUID:{}", uuid);
        return successQueryBaseResponse();
    }

    @ApiOperation("邮箱验证码发送接口")
    @PostMapping("/email")
    public BaseResponse sendEmailVerifyCode(@RequestBody EmailVerifyCodeReq verifyCodeReq, HttpServletRequest request) {
        String uuid = UUIDUtil.randomUUID();
        log.info("请求开始 验证码发送接口: 请求参数：{}，UUID:{}", verifyCodeReq, uuid);
        verifyCodeReq.setIpAdd(IpAddressUtil.get(request));
        verifyCodeService.sendEmail(verifyCodeReq);
        log.info("请求结束： UUID:{}", uuid);
        return successQueryBaseResponse();
    }
}
